home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / prm < prev    next >
Encoding:
Text File  |  2002-06-04  |  5.5 KB  |  205 lines

  1. #!/bin/sh
  2. # prm - package remove script
  3. # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
  4. # released under gpl.
  5. # $1: package to remove.  can be full pathname, relative to build root,
  6. #     relative to current dir, relative to col/install/RPMS,
  7. #     relative to col/install/SRPMS, or just rpm package name
  8. # ex: prm /opt/redmondLinux/builds/21/col/install/SRPMS/mypackage-1.1-1.src.rpm
  9. # ex: prm col/install/SRPMS/mypackage-1.1-1.src.rpm
  10. # ex: prm mypackage-1.1-1.src.rpm
  11. # ex: prm mypackage
  12. # opts: -q: quiet [don't print status messages]
  13. #    -d: dry run [don't actually perform remove]
  14. #    -v: verbose
  15. #    -l: language to remove from [default: all languages]
  16.  
  17. # BUG: use getopts instead
  18. LANG=
  19. ERROR=0
  20.  
  21. if [ "n$1" = "n-q" ]; then # -q
  22.   QUIET="-q"
  23.   shift
  24. fi
  25.  
  26. if [ "n$1" = "n-d" ]; then # -d
  27.   DRY_RUN="-d"
  28.   shift
  29. fi
  30.  
  31. if [ "n$1" = "n-v" ]; then # -v
  32.   VERBOSE="-v"
  33.   shift
  34. fi
  35.  
  36. if [ "n$1" = "n-l" ]; then # -l
  37.   LANG="$2"
  38.   shift
  39.   shift
  40. fi
  41.  
  42. if [ "$#" -lt 1 ]; then # no args
  43. ( echo `basename $0`: no arguments given
  44.   echo
  45.   echo usage: `basename $0` \[-q\] \[-d\] \[-v\] \[-l lang\] package.rpm
  46.   echo removes package in redmond linux build system
  47.   echo -q is quiet, ie don\'t print status messages
  48.   echo -d is dry run, ie don\'t perform the rm
  49.   echo -v is verbose
  50.   echo -l is language or all if not present ) >&2
  51.   exit 1
  52. fi 
  53.  
  54.  
  55. # constants and vars
  56.  
  57. RL_ROOT=/opt/redmondlinux
  58. BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
  59. BUILD_NUM=`cat $BUILD_NUM_FILE`
  60.  
  61. BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
  62.  
  63. cd $BUILD_ROOT
  64. LANG_TO_PROCESS=`echo ${LANG}*`
  65. cd -
  66. [ $VERBOSE ] && echo Languages to process: $LANG_TO_PROCESS
  67.  
  68. while [ 1 ]; do # poor substitute for a do..until loop
  69.  
  70. # check for the file
  71.  
  72.   unset PATH_NAME UPDATED_FILE
  73.   MATCH_FOUND=0
  74.  
  75.   for lang in $LANG_TO_PROCESS; do # check for each language
  76.     [ $VERBOSE ] && echo checking $lang
  77.  
  78.  
  79.     if [ -r "$1" ]; then
  80. # file found full pathname and relative to current dir cases
  81. # get fully qualified file name
  82.       pushd `dirname "$1"` > /dev/null
  83.       PATH_NAME=`pwd`/`basename "$1"`
  84.       popd > /dev/null
  85.       MATCH_FOUND=1
  86.  
  87.     elif [ -r "$BUILD_ROOT/$lang/$1" ]; then
  88. # file found relative to build root
  89. # get fully qualified file name
  90.       pushd `dirname "$BUILD_ROOT/$lang/$1"` > /dev/null
  91.       PATH_NAME=`pwd`/`basename "$1"`
  92.       popd > /dev/null
  93.       MATCH_FOUND=1
  94.  
  95.     elif [ -r "$BUILD_ROOT/$lang/rl/install/RPMS/$1" ]; then
  96. # file found relative to rl/install/RPMS
  97. # get fully qualified file name
  98.       pushd `dirname "$BUILD_ROOT/$lang/rl/install/RPMS/$1"` > /dev/null
  99.       PATH_NAME=`pwd`/`basename "$1"`
  100.       popd > /dev/null
  101.       MATCH_FOUND=1
  102.  
  103.     elif [ -r "$BUILD_ROOT/$lang/rl/install/SRPMS/$1" ]; then
  104. # file found relative to rl/install/SRPMS
  105. # get fully qualified file name
  106.       pushd `dirname "$BUILD_ROOT/$lang/rl/install/SRPMS/$1"` > /dev/null
  107.       PATH_NAME=`pwd`/`basename "$1"`
  108.       popd > /dev/null
  109.       MATCH_FOUND=1
  110.  
  111.     elif { PATH_TEST=`echo $BUILD_ROOT/$lang/rl/install/RPMS/$1-[0-9]*.rpm`;
  112.       [ "n$PATH_TEST" != "n" -a -r "$PATH_TEST" ]; }; then
  113. # file found rpm package name in rl/install/RPMS
  114.  
  115. # BUG: assumes no numbers start sections of package name
  116. # [myfile-1st-demo-1.2-21rl.rpm would erroneously match "myfile"]
  117. # BUG: assumes no letters start versions of package
  118. # [myfile-a123-21rl.rpm would erroneously not match "myfile"]
  119.  
  120. # these bugs are trivial IMHO because they can be matched precisely by
  121. # other methods, above
  122.  
  123. # get fully qualified file name
  124.       pushd `dirname "$PATH_TEST"` > /dev/null
  125.       PATH_NAME=`pwd`/`basename "$PATH_TEST"`
  126.       popd > /dev/null
  127.       MATCH_FOUND=1
  128.  
  129.     elif { PATH_TEST=`echo $BUILD_ROOT/$lang/rl/install/SRPMS/$1-[0-9]*.rpm`;
  130.       [ "n$PATH_TEST" != "n" -a -r "$PATH_TEST" ]; }; then
  131. # file found rpm package name in rl/install/SRPMS
  132.  
  133. # same bugs as above for rl/install/RPMS
  134.  
  135. # get fully qualified file name
  136.       pushd `dirname "$PATH_TEST"` > /dev/null
  137.       PATH_NAME=`pwd`/`basename "$PATH_TEST"`
  138.       popd > /dev/null
  139.       MATCH_FOUND=1
  140.     fi # big if/elif find file tree
  141.  
  142.     if [ "n$PATH_NAME" = "n" ]; then # file doesn't exist
  143.       echo $1 not found in \[$lang\]
  144.     else # if file exists
  145.       [ $VERBOSE ] && echo file found\!  $PATH_NAME
  146.  
  147. # binary rpm?  if so we need to update pkgs.db
  148.  
  149.       if [ `basename "$PATH_NAME" .i386.rpm`.i386.rpm = `basename "$PATH_NAME"` -o \
  150.     `basename "$PATH_NAME" .i486.rpm`.i486.rpm = `basename "$PATH_NAME"` -o \
  151.     `basename "$PATH_NAME" .i586.rpm`.i586.rpm = `basename "$PATH_NAME"` -o \
  152.     `basename "$PATH_NAME" .noarch.rpm`.noarch.rpm = `basename "$PATH_NAME"` ]; then
  153. # yes, binary rpm
  154.  
  155.  
  156. #
  157. #
  158. # update pkgs.db
  159.  
  160. # constants and vars
  161.  
  162.     UPDATED_FILE="$PATH_NAME"
  163.  
  164. # get needed info
  165.  
  166.     eval `rpmextr --shell $UPDATED_FILE` # package name
  167.     PKGS_DB=$BUILD_ROOT/$lang/rl/data/pkgs.db
  168.     DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB` # line from DB
  169.  
  170.       else # not a binary rpm
  171.     [ $VERBOSE ] && echo not a binary rpm
  172.       fi # binary rpm
  173.  
  174.  
  175. # perform rm
  176.  
  177.       [ $VERBOSE ] && echo frm $QUIET $VERBOSE -l $lang "$PATH_NAME"
  178.       [ $DRY_RUN ] || frm $QUIET $VERBOSE -l $lang "$PATH_NAME"
  179.       RETURN=$?
  180.       [ $VERBOSE ] && echo frm returned $RETURN
  181.       [ $RETURN -gt 0 ] && exit $RETURN # assumes frm will print error msg
  182.  
  183.       if [ "n$UPDATED_FILE" != "n" ]; then # update pkgs.db
  184.     [ $VERBOSE ] && echo -n binary rpm,\ 
  185.     echo current line \[$lang\]: $DB_LINE
  186.     echo it will need removing
  187.       fi
  188.  
  189.     fi # file doesn't exist
  190.  
  191.   done # for each language
  192.  
  193.   if [ $MATCH_FOUND = 0 ]; then
  194.     [ $VERBOSE ] && echo no match found\!  time to leave...
  195.     break
  196.   fi
  197.  
  198. done # poor substitute for a do..until loop
  199.